home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / P_ROBO31.ZIP / HOTSHOT3.PR < prev    next >
Text File  |  1993-02-21  |  7KB  |  201 lines

  1.   PROCEDURE HotShot3;
  2.   {
  3.    Author: David Malmberg
  4.  
  5.    Strategy:  Stay in one place.  Find a foe.  Take a shot.
  6.    Keep improving aim and shooting until foe is lost from sights.
  7.    Then move sights (scanning) to adjacent target area.
  8.    If the Robot scans a complete circle (360 degrees) without
  9.    finding a foe in shooting range, move to another spot on the
  10.    field.  (This will avoid "stand-offs" where opponents stay
  11.    just out of range of one another.)  RaiseShield when standing
  12.    still and lower them when moving.
  13.  
  14.    When damage gets to 70 (or more) or fuel (if using fuel) gets
  15.    below 200 adopt an "End-Game" strategy of moving to the lower
  16.    left corner, lower shield, and continue to scan and shoot in
  17.    the corner's 90 degree range.
  18.  
  19.    This Robot should be VERY effective against foes which
  20.    are stopped or are moving slowly.  It will be less effective
  21.    against Robots traveling at high speeds.
  22.  
  23.    This Robot has been designed to utilize Fuel (if it is available)
  24.    to power its Shield.  It has also been designed to deal with
  25.    Obstructions (if any) by moving around them.
  26.   }
  27.  
  28.  
  29.   VAR { HotShot3 "Global" variables }
  30.  
  31.     Angle, { Scanning angle }
  32.     Last_Damage, { Robot's Last damage value }
  33.     Range, { Range/Distance to foe }
  34.     Sweep, { "Sweep count" -- when = 18, Robot has scanned 360 degrees }
  35.     Delta          : Integer; { Scanning arc }
  36.  
  37.  
  38.     PROCEDURE Aim(VAR Ang : Integer; VAR Arc : Integer);
  39. {
  40.  Improve aim by doing a binary search of the target area.
  41.  I.E., divide the target area in two equal pieces and redefine
  42.  the target area to be the piece where the foe is found.
  43.  If the foe is not found, expand the search area to the
  44.  maximum arc of plus or minus 10 degrees.
  45. }
  46.     BEGIN
  47.       Arc := Arc DIV 2; { Divide search area in two. }
  48.       IF scan(Ang-Arc, Arc) <> 0 { Check piece "below" target angle. }
  49.         THEN Ang := Ang-Arc { If foe found, redefine target angle. }
  50.         ELSE IF scan(Ang+Arc, Arc) <> 0 { Check piece "above" target angle. }
  51.           THEN Ang := Ang+Arc { If foe found, redefine target angle. }
  52.           ELSE Arc := 10;
  53.       { Foe not found in either piece, expand search area to maximum arc. }
  54.     END; {Aim}
  55.  
  56.     PROCEDURE BlastThem;
  57.     BEGIN
  58.       Angle := 10;
  59.       REPEAT
  60.         Delta := 10; { Start with widest scanning arc. }
  61.         Range := scan(Angle, Delta);
  62.         WHILE (Range > 40) AND (ObjectScanned = Enemy)
  63.           AND (Range < MaxMissileRange) DO
  64.         { Must be far enough away to avoid self-damage. }
  65.           BEGIN
  66.             Aim(Angle, Delta); { Improve aim. }
  67.             Cannon(Angle, Range); { Fire!! }
  68.             Range := scan(Angle, Delta); { Is foe still in sights? }
  69.           END;
  70.         Angle := Angle+20; { Look in adjacent target area. }
  71.       UNTIL Angle > 360;
  72.     END;
  73.  
  74.  
  75.     PROCEDURE GOTO(x, y : Integer);
  76.       { Go to location X,Y on playing field. }
  77.     VAR Heading    : Integer;
  78.     BEGIN
  79.       { WARNING:  If the point X,Y is inside an Obstruction then }
  80.       { executing this routine will cause the Robot to commit }
  81.       { suicide by repeatedly running into the wall of the Obstruction. }
  82.       { First, find the heading we need to get to the desired spot. }
  83.       Heading := Angle_To(x, y);
  84.  
  85.       { Keep traveling at top speed until we are within 150 meters }
  86.       WHILE (distance(loc_x, loc_y, x, y) > 150) DO
  87.         BEGIN
  88.           Drive(Heading, MaxSpeed);
  89.           BlastThem;
  90.         END;
  91.  
  92.       { Cut speed, and creep the rest of the way. }
  93.       WHILE (distance(loc_x, loc_y, x, y) > 20) DO
  94.         BEGIN
  95.           Drive(Heading, 20);
  96.           BlastThem;
  97.         END;
  98.  
  99.       { Stop driving, should coast to a stop. }
  100.       Drive(Heading, 0); {I.E., Stop}
  101.     END; {GoTo(X,Y)}
  102.  
  103.  
  104.     PROCEDURE Ramble(X, Y : Integer);
  105.       { Move to X, Y (if possible) on the playing field }
  106.       { by avoiding Obstructions - if any.              }
  107.     VAR Heading, Tries, Dist : Integer;
  108.     BEGIN
  109.       Tries := 0;
  110.       Heading := Angle_To(X, Y);
  111.       Drive(Heading, 100); {Start off at maximum speed}
  112.       Dist := Scan(Heading, 5);
  113.       REPEAT
  114.         IF ObjectScanned = Obstruction
  115.           THEN BEGIN
  116.             REPEAT
  117.               Heading := Heading + 10;
  118.               Dist := Scan(Heading, 5);
  119.             UNTIL ObjectScanned <> Obstruction;
  120.             Drive(Heading, 50); {Minimum speed to turn freely}
  121.           END;
  122.         Heading := Angle_To(X, Y);
  123.         Dist := Scan(Heading, 5);
  124.         Tries := Tries + 1;
  125.       UNTIL (ObjectScanned <> Obstruction) OR (Tries > 20);
  126.       IF (ObjectScanned <> Obstruction) THEN GOTO(X,Y);
  127.     END; {Ramble}
  128.  
  129.  
  130.     PROCEDURE Move;
  131.       { Move to a random spot on the playing field. }
  132.     VAR x, y       : Integer;
  133.     BEGIN
  134.       Sweep := 0; { Reset Sweep counter to zero. }
  135.       x := Random(900)+50;
  136.       y := Random(900)+50;
  137.       Ramble(x, y);
  138.     END; {Move}
  139.  
  140.  
  141.   PROCEDURE End_Game;
  142.  
  143.   BEGIN {End_Game}
  144.     Ramble(0,0); {Lower Left Corner}
  145.     Angle := 10; {Sweep arc from 0 to 90 degrees only}
  146.     REPEAT
  147.       Delta := 10; { Start with widest scanning arc. }
  148.       Range := scan(Angle, Delta);
  149.       WHILE (Range > 40) AND (Range < 700) AND (ObjectScanned = Enemy)
  150.         DO { Must be far enough away to avoid self-damage. }
  151.         BEGIN
  152.           Aim(Angle, Delta); { Improve aim. }
  153.           IF ObjectScanned = Enemy
  154.             THEN cannon(Angle, Range); { Fire!! }
  155.           Range := scan(Angle, Delta); { Is foe still in sights? }
  156.         END;
  157.       Angle := Angle+20; { Look in adjacent target area. }
  158.       IF Angle > 90 THEN Angle := 10;
  159.     UNTIL Dead OR Winner;
  160.   END; {End_Game}
  161.  
  162.  
  163.   BEGIN {HotShot3 Main}
  164.     RaiseShield;
  165.     Angle := 0;
  166.     Ramble(500, 500); { Move to center of field -- if possible. }
  167.     Sweep := 0; { Initialize Sweep counter to zero. }
  168.     REPEAT { Until Dead or Winner }
  169.       Delta := 10; { Start with widest scanning arc. }
  170.       Range := scan(Angle, Delta);
  171.       WHILE (Range > 40) AND (Range < MaxMissileRange)
  172.         AND (ObjectScanned = Enemy)
  173.         DO { Must be far enough away to avoid self-damage. }
  174.         BEGIN
  175.           Sweep := 0; { Found foe, so reset Sweep to zero }
  176.           Aim(Angle, Delta); { Improve aim. }
  177.           IF ObjectScanned = Enemy
  178.             THEN cannon(Angle, Range); { Fire!! }
  179.           Range := scan(Angle, Delta); { Is foe still in sights? }
  180.         END;
  181.       Angle := Angle+20; { Look in adjacent target area. }
  182.       Sweep := Sweep+1;
  183.       IF Sweep = 18 THEN
  184.         BEGIN { If robot has scanned a full circle, move elsewhere. }
  185.           LowerShield; {Don't need shield (as much) when moving}
  186.           Move;
  187.         END;
  188.  
  189.       RaiseShield; {Standing still so use shield}
  190.  
  191.       {"End" game strategy}
  192.       IF (Fuel < 200) OR (Damage > 70) THEN End_Game;
  193.  
  194.     UNTIL Dead OR Winner;
  195.  
  196.   END; {HotShot3 Main}
  197.  
  198.  
  199.  
  200.  
  201.